
//
//  JQHomeBannerCollectionReusableView.m
//  JQLive
//
//  Created by Bruce on 20/8/12.
//  Copyright © 2020年 JQLive. All rights reserved.
//

#import "JQHomeBannerCollectionReusableView.h"
#import "WMZBannerView.h"
#import "UIView+Extension.h"
#import "JQHomeBannerCollectionCell.h"
#import "JQHomeBannerModel.h"

@interface JQHomeBannerCollectionReusableView()
@property (nonatomic, strong) WMZBannerView *bannerView;
@property (nonatomic, strong)  UIView *topBannerView;
@end

@implementation JQHomeBannerCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        //      self.backgroundColor = MYHome_backgroundColor;
        // 上半角
        //      [self round:12 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
        
        UIView *topBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 144+20)];
        //        topBackGroundView.backgroundColor = MYHome_backgroundColor;
        [self addSubview:topBackGroundView];
        
        UIView *topWhiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 10+17, SCREEN_WIDTH, 144-27+20)];
        topWhiteView.backgroundColor = [UIColor whiteColor];
        [topWhiteView round:20 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
        [self addSubview:topWhiteView];
        
        
        UIView *topBannerView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH-20, 144)];
        //        topBannerView.backgroundColor = [UIColor blueColor];
        [topBannerView round:10 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
        [self addSubview:topBannerView];
        self.topBannerView = topBannerView;
        topBannerView.backgroundColor = [UIColor clearColor];
        
        //          //模拟刷新数据
        //          dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //              param.wDataSet([self getData]);
        //              [viewOne updateUI];
        //          });
        
        
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(18, 144+12+20, 15, 22)];
        imageV.image = [UIImage svgImageNamed:@"home_hotLive" size:CGSizeMake(15, 22)];
        [self addSubview:imageV];
        
        self.title = [[UILabel alloc] initWithFrame:CGRectMake(15+18+8, 144+12+20, 300, 22)];
        self.title.textColor = [UIColor blackColor];
        [self addSubview:self.title];
        
        
        // 添加阴影
        UIView *view = [[UIView alloc] init];
        view.frame = CGRectMake(10,144+20-10-48,SCREEN_WIDTH-20,48);
        // gradient
        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0,0,SCREEN_WIDTH-20,48);
        gl.startPoint = CGPointMake(0, 0);
        gl.endPoint = CGPointMake(0, 1);
        //        view.backgroundColor = [UIColor whiteColor];
        gl.colors = @[(__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.0].CGColor, (__bridge id)[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.8].CGColor];
        gl.locations = @[@(0), @(1.f)];
        //        view.layer.cornerRadius = 10;
        [self addSubview:view];
        [view.layer addSublayer:gl];
        
    }
    return self;
}
- (void)updataWithBanner{
    /*
     *横向
     */
    WMZBannerParam *param = [WMZBannerParam new];
    //自定义视图必传
    param.wMyCellClassNameSet(@"JQHomeBannerCollectionCell");
    param.wMyCellSet(^UICollectionViewCell *(NSIndexPath *indexPath, UICollectionView *collectionView, id model, UIImageView *bgImageView,NSArray*dataArr) {
        
        JQHomeBannerCollectionCell *cell = (JQHomeBannerCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([JQHomeBannerCollectionCell class]) forIndexPath:indexPath];
        JQHomeBannerData *data = (JQHomeBannerData *)model;
        [cell setCoverImageView:data.img titleStr:data.title];
        
        return cell;
    });
    param.wFrameSet(CGRectMake(0, 0, BannerWitdh-20, 144));
    //            if (self.dataArr.count == 0) {
    //                JQHomeBannerData *data = [[JQHomeBannerData alloc] init];
    //                data.img = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1576744105022&di=f4aadd0b85f93309a4629c998773ae83&imgtype=0&src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fwallpaper%2F1206%2F07%2Fc0%2F11909864_1339034191111.jpg";
    //                data.title = @"测试1234";
    //                NSMutableArray<JQHomeBannerData *> *arrM = [NSMutableArray arrayWithObject:data];
    //                self.dataArr = [arrM copy];
    //            }
    
    param.wDataSet(self.dataArr);
    //        param.w
    //开启循环滚动
    param.wRepeatSet(YES);
    //设置item的间距
    param.wLineSpacingSet(10);
    //开启自动滚动
    param.wAutoScrollSet(YES);
    //自动滚动时间
    param.wAutoScrollSecondSet(3);
    param.wBannerControlPositionSet(BannerControlRight);
    param.wBannerControlSelectColorSet([UIColor whiteColor]);
    param.wBannerControlColorSet([[UIColor whiteColor] colorWithAlphaComponent:0.2]);
    //        param.wBannerControlImageSizeSet(CGSizeMake(5, 5));
    param.wBannerControlSpacingSet(12);
    WMZBannerView *bannerView = [[WMZBannerView alloc]initConfigureWithModel:param];
    if (self.bannerView) {
        self.bannerView = bannerView;
    }else{
        [self.topBannerView addSubview:bannerView];
        self.bannerView = bannerView;
    }
}

@end
